import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import axios from 'axios'
// 导入表格插件，吐槽vue怎么搜索的插件好多名字类似
import TreeTable from 'vue-table-with-tree-grid'

// 导入fonticon字体图标
import './assets/fonts/iconfont.css'
// 导入全局样式表
import './assets/css/global.css'

process.env.NODE_ENV === 'development' && require('./mock')
console.log('当前环境', process.env)

// 将axios实例挂载到Vue的原型中，这样可以在vue实例中通过this.$http拿到axios
Vue.prototype.$http = axios.create({
  baseURL: 'http://localhost:3000/api/v1/',
  timeout: 2500
  // headers: { 'X-Custom-Header': 'e6d675ba-9350-4370-b5a5-d486ce53e4c3' }
})

// 配置axios（只有一个配置的时候，建议用上面的配置方法，因为项目不会只请求一个项目的接口）
// axios.defaults.baseURL = 'http://localhost:3000/api/v1/'
// axios.defaults.timeout = 2500
// axios.defaults.headers.post['Content-Type'] = 'application/json'
// axios.defaults.headers.common.tooken = window.sessionStorage.getItem('token')
// Vue.prototype.$http = axios

axios.interceptors.request.use(config => {
  // console.log(config)
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})

Vue.config.productionTip = false

Vue.component('tree-table', TreeTable)

Vue.filter('dateFormat', function (oldValue) {
  const date = new Date(oldValue)

  const year = date.getFullYear()
  const month = (date.getMonth() + 1 + '').padStart(2, '0')
  const day = (date.getDate() + '').padStart(2, '0')

  const hour = (date.getHours() + '').padStart(2, '0')
  const minute = (date.getMinutes() + '').padStart(2, '0')
  const second = (date.getSeconds() + '').padStart(2, '0')

  return `${year}-${month}-${day} ${hour}:${minute}:${second}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
